From 8161f8dcca12e595b0121181c7ec546c767b58c4 Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Sat, 26 Nov 2016 11:51:30 +0100 Subject: [PATCH] rendericon: Pass the scale factor when rendeirng textures Fixes icon rendeirng on hidpi. --- gtk/gtkiconhelper.c | 5 ++++- gtk/gtkrendericon.c | 24 +++++++++++++----------- gtk/gtkrendericonprivate.h | 3 ++- gtk/gtksnapshot.c | 3 ++- 4 files changed, 21 insertions(+), 14 deletions(-) diff --git a/gtk/gtkiconhelper.c b/gtk/gtkiconhelper.c index f3b66216a6..fee8bd641d 100644 --- a/gtk/gtkiconhelper.c +++ b/gtk/gtkiconhelper.c @@ -871,7 +871,10 @@ gtk_icon_helper_snapshot (GtkIconHelper *self, style = gtk_css_node_get_style (gtk_css_gadget_get_node (GTK_CSS_GADGET (self))); - gtk_css_style_snapshot_icon_texture (style, snapshot, texture); + gtk_css_style_snapshot_icon_texture (style, + snapshot, + texture, + gtk_widget_get_scale_factor (gtk_css_gadget_get_owner (GTK_CSS_GADGET (self)))); } gboolean diff --git a/gtk/gtkrendericon.c b/gtk/gtkrendericon.c index 7355ebed26..b20b743903 100644 --- a/gtk/gtkrendericon.c +++ b/gtk/gtkrendericon.c @@ -249,23 +249,25 @@ gtk_css_style_render_icon_get_extents (GtkCssStyle *style, void gtk_css_style_snapshot_icon_texture (GtkCssStyle *style, GtkSnapshot *snapshot, - GskTexture *texture) + GskTexture *texture, + double texture_scale) { const GtkCssValue *shadows, *transform; - graphene_matrix_t transform_matrix, m1, m2, m3, saved_matrix; + graphene_matrix_t transform_matrix, translate, matrix, saved_matrix; graphene_rect_t bounds; GskRenderNode *node; - int width, height; + double width, height; static gboolean shadow_warning; g_return_if_fail (GTK_IS_CSS_STYLE (style)); g_return_if_fail (snapshot != NULL); g_return_if_fail (GSK_IS_TEXTURE (texture)); + g_return_if_fail (texture_scale > 0); shadows = gtk_css_style_get_value (style, GTK_CSS_PROPERTY_ICON_SHADOW); transform = gtk_css_style_get_value (style, GTK_CSS_PROPERTY_ICON_TRANSFORM); - width = gsk_texture_get_width (texture); - height = gsk_texture_get_height (texture); + width = gsk_texture_get_width (texture) / texture_scale; + height = gsk_texture_get_height (texture) / texture_scale; if (!gtk_css_transform_value_get_matrix (transform, &transform_matrix)) return; @@ -273,13 +275,13 @@ gtk_css_style_snapshot_icon_texture (GtkCssStyle *style, graphene_matrix_init_from_matrix (&saved_matrix, gtk_snapshot_get_transform (snapshot)); /* XXX: Implement -gtk-icon-transform-origin instead of hardcoding "50% 50%" here */ - graphene_matrix_init_translate (&m1, &GRAPHENE_POINT3D_INIT(width / 2.0, height / 2.0, 0)); - graphene_matrix_multiply (&transform_matrix, &m1, &m3); - graphene_matrix_init_translate (&m2, &GRAPHENE_POINT3D_INIT(- width / 2.0, - height / 2.0, 0)); - graphene_matrix_multiply (&m2, &m3, &m1); - gtk_snapshot_transform (snapshot, &m1); + graphene_matrix_init_translate (&translate, &GRAPHENE_POINT3D_INIT(width / 2.0, height / 2.0, 0)); + graphene_matrix_multiply (&transform_matrix, &translate, &matrix); + graphene_matrix_translate (&matrix, &GRAPHENE_POINT3D_INIT(- width / 2.0, - height / 2.0, 0)); + graphene_matrix_scale (&matrix, 1.0 / texture_scale, 1.0 / texture_scale, 1); + gtk_snapshot_transform (snapshot, &matrix); - graphene_rect_init (&bounds, 0, 0, width, height); + graphene_rect_init (&bounds, 0, 0, gsk_texture_get_width (texture), gsk_texture_get_height (texture)); node = gtk_snapshot_append (snapshot, &bounds, "Icon"); if (!_gtk_css_shadows_value_is_none (shadows) && !shadow_warning) diff --git a/gtk/gtkrendericonprivate.h b/gtk/gtkrendericonprivate.h index 6a3ca4b911..2ab38f7699 100644 --- a/gtk/gtkrendericonprivate.h +++ b/gtk/gtkrendericonprivate.h @@ -49,7 +49,8 @@ void gtk_css_style_render_icon_surface (GtkCssStyle *style, double y); void gtk_css_style_snapshot_icon_texture (GtkCssStyle *style, GtkSnapshot *snapshot, - GskTexture *texture); + GskTexture *texture, + double texture_scale); void gtk_css_style_render_icon_get_extents (GtkCssStyle *style, GdkRectangle *extents, diff --git a/gtk/gtksnapshot.c b/gtk/gtksnapshot.c index 99d7ea5e5a..5ec1d56aa9 100644 --- a/gtk/gtksnapshot.c +++ b/gtk/gtksnapshot.c @@ -688,7 +688,8 @@ gtk_snapshot_render_icon (GtkSnapshot *snapshot, gtk_snapshot_translate_2d (snapshot, x, y); gtk_css_style_snapshot_icon_texture (gtk_style_context_lookup_style (context), snapshot, - texture); + texture, + 1); gtk_snapshot_translate_2d (snapshot, -x, -y); gsk_texture_unref (texture); } -- 2.30.2